<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>智慧生活 | 感谢有你</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="${rc.contextPath}/static/bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="${rc.contextPath}/static/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="${rc.contextPath}/static/css/ionicons.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="${rc.contextPath}/static/dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="${rc.contextPath}/static/dist/css/skins/_all-skins.min.css">
    <link rel="stylesheet" href="${rc.contextPath}/static/plugins/datatables/dataTables.bootstrap.css">
    <link rel="stylesheet" href="${rc.contextPath}/static/plugins/daterangepicker/daterangepicker.css">
    <link rel="stylesheet" href="${rc.contextPath}/static/plugins/datepicker/datepicker3.css">
</head>
<!-- ADD THE CLASS fixed TO GET A FIXED HEADER AND SIDEBAR LAYOUT -->
<!-- the fixed layout is not compatible with sidebar-mini -->
<body class="hold-transition skin-blue fixed sidebar-mini">
<#include "/templete/templete.ftl"/>
<!-- Site wrapper -->
<div class="wrapper">
    <!-- 引入导航栏和菜单栏-->
    <@header/>
    <!-- =============================================== -->
    <!-- 主界面 -->
    <div class="content-wrapper">
        <section class="content">
            <div class="box">
                <div class="box-search">
                    <form onSubmit="return false;" id="attendQueryForm">
                        <div class="form-inline">
                            <label>日期范围:</label>
                            <div class="input-group">
                                <div class="input-group-addon">
                                    <i class="fa fa-calendar"></i>
                                </div>
                                <input type="text" class="form-control pull-left" id="rangeDate" name="rangeDate">
                            </div>
                            <label>状态</label>
                            <select class="form-control" name="attendStatus" id="attendStatus">
                                <option value="">全部</option>
                                <option value="1">正常</option>
                                <option value="2">异常</option>
                            </select>
                            <button type="submit" class="btn btn-primary" onclick="attendQuery()">查询</button>
                        </div>
                    </form>
                </div>

                <!-- /.box-header -->
                <!-- /.box-header -->
                <div class="box-body">
                    <table id="attend_grid" class="table table-bordered table-striped">
                        <thead>
                        <tr>
                            <th>序号</th>
                            <th>考勤日期</th>
                            <th>星期</th>
                            <th>早打卡</th>
                            <th>晚打卡</th>
                            <th>缺勤时长</th>
                            <th>考勤状态</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                    </table>
                </div>
                <div id="grid_pager"></div>

            </div>
        </section>

    </div>
    <!-- /.content-wrapper -->
    <!-- =============================================== -->
    <!-- 引入底部-->
    <@footer/>
    <div class="control-sidebar-bg"></div>

</div>
<!-- ./wrapper -->

<!-- jQuery 2.2.3 -->
<script src="${rc.contextPath}/static/plugins/jQuery/jquery-2.2.3.min.js"></script>
<!-- Bootstrap 3.3.6 -->
<script src="${rc.contextPath}/static/bootstrap/js/bootstrap.min.js"></script>
<!-- SlimScroll -->
<script src="${rc.contextPath}/static/plugins/slimScroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="${rc.contextPath}/static/plugins/fastclick/fastclick.js"></script>
<!-- AdminLTE App -->
<script src="${rc.contextPath}/static/dist/js/app.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="${rc.contextPath}/static/dist/js/demo.js"></script>
<script src="${rc.contextPath}/static/plugins/datepicker/bootstrap-datepicker.js"></script>
<script src="${rc.contextPath}/static/plugins/daterangepicker/moment.min.js"></script>
<script src="${rc.contextPath}/static/plugins/daterangepicker/daterangepicker.js"></script>
<script src="${rc.contextPath}/static/plugins/datepicker/locales/bootstrap-datepicker.zh-CN.js"></script>
<script src="${rc.contextPath}/static/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="${rc.contextPath}/static/plugins/datatables/dataTables.bootstrap.min.js"></script>
<script src="${rc.contextPath}/static/dist/js/html5shiv.min.js"></script>
<script src="${rc.contextPath}/static/dist/js/respond.min.js"></script>
<script>

    /* 日历*/
    //Date range as a button
    $('#rangeDate').daterangepicker(
        {
            locale: {
                applyLabel: '确定',
                cancelLabel: '取消',
                fromLabel: '起始时间',
                toLabel: '结束时间',
                customRangeLabel: '自定义',
                daysOfWeek: ['日', '一', '二', '三', '四', '五', '六'],
                monthNames: ['一月', '二月', '三月', '四月', '五月', '六月',
                    '七月', '八月', '九月', '十月', '十一月', '十二月'],
                firstDay: 1,
                format: "YYYY-MM-DD",
                separator: "/",
            },

            ranges: {
                '今天': [moment()],
                '昨天': [moment().subtract(1, 'days')],
                '最近七天': [moment().subtract(6, 'days'), moment()],
                '最近30天': [moment().subtract(29, 'days'), moment()],
                '本月': [moment().startOf('month'), moment().endOf('month')],
                '上月': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
            },
            startDate: moment().startOf('month'),
            endDate: moment().endOf('month')
        }
    );

    Date.prototype.format = function (fmt) {
        var o = {
            "M+": this.getMonth() + 1,                 //月份
            "d+": this.getDate(),                    //日
            "h+": this.getHours(),                   //小时
            "m+": this.getMinutes(),                 //分
            "s+": this.getSeconds(),                 //秒
            "q+": Math.floor((this.getMonth() + 3) / 3), //季度
            "S": this.getMilliseconds()             //毫秒
        };
        if (/(y+)/.test(fmt)) {
            fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        }
        for (var k in o) {
            if (new RegExp("(" + k + ")").test(fmt)) {
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
            }
        }
        return fmt;
    }
    //Date picker
    $('#attendDate').datepicker({
        autoclose: true,
        language: 'zh-CN',
        todayHighlight: true
    });
    function reAttend(data) {
        alert(data.id + data.attendDate);
        $("#reAttendModal").modal('show');
    }
    var week_CN = ["周一", "周二", "周三", "周四", "周五", "周六", "周日"]
    function formToJson(form) {
        var result = {};
        var fieldArray = $('#' + form).serializeArray();
        for (var i = 0; i < fieldArray.length; i++) {
            var field = fieldArray[i];
            if (field.name in result) {
                result[field.name] += ',' + field.value;
            } else {
                result[field.name] = field.value;
            }
        }
        return result;
    }
    var table;
    var requestUrl = "${rc.contextPath}/attend/attendList";
    function attendQuery() {
        table.ajax.reload();
    }
    $(function () {
        //提示信息
        $.fn.dataTable.ext.errMode = 'none';
        var lang = {
            "sProcessing": "处理中...",
            "sLengthMenu": "每页 _MENU_ 项",
            "sZeroRecords": "没有匹配结果",
            "sInfo": "当前显示第 _START_ 至 _END_ 项，共 _TOTAL_ 项。",
            "sInfoEmpty": "当前显示第 0 至 0 项，共 0 项",
            "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
            "sInfoPostFix": "",
            "sSearch": "搜索:",
            "sUrl": "",
            "sEmptyTable": "表中数据为空",
            "sLoadingRecords": "载入中...",
            "sInfoThousands": ",",
            "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "上页",
                "sNext": "下页",
                "sLast": "末页",
                "sJump": "跳转"
            },
            "oAria": {
                "sSortAscending": ": 以升序排列此列",
                "sSortDescending": ": 以降序排列此列"
            }
        };
        table = $("#attend_grid").dataTable({
            language: lang, //提示信息
            autoWidth: false, //禁用自动调整列宽
            stripeClasses: ["odd", "even"], //为奇偶行加上样式，兼容不支持CSS伪类的场合
            processing: true, //隐藏加载提示,自行处理
            serverSide: true, //启用服务器端分页
            searching: false, //禁用原生搜索
            orderMulti: false, //启用多列排序
            order: [], //取消默认排序查询,否则复选框一列会出现小箭头
            renderer: "bootstrap", //渲染样式：Bootstrap和jquery-ui
            columnDefs: [{
                "targets": 'nosort', //列的样式名
                "orderable": false //包含上样式名‘nosort'的禁止排序
            }],
            ajax: function (data, callback, settings) {
                var param = formToJson("attendQueryForm");
                param.pageSize = data.length;//页面显示记录条数，在页面显示每页显示多少项的时候
                param.start = data.start;//开始的记录序号
                param.currentPage = (data.start / data.length) + 1;//当前页码
                $.ajax({
                    type: "GET",
                    url: requestUrl,
                    cache: false, //禁用缓存
                    data: param, //传入组装的参数
                    dataType: "json",
                    success: function (result) {
                        setTimeout(function () {
                            //封装返回数据
                            var returnData = {};
                            returnData.draw = data.startRow;//这里直接自行返回了draw计数器,应该由后台返回
                            returnData.recordsTotal = result.total;//返回数据全部记录
                            returnData.recordsFiltered = result.total;//后台不实现过滤功能，每次查询均视作全部结果
                            returnData.data = result.list;//返回的数据列表
                            //此时的数据需确保正确无误，异常判断应在执行此回调前自行处理完毕
                            callback(returnData);
                        }, 200);
                    }
                });
            },
            columns: [
                {
                    "data": "seq",
                    render: function (data, type, full, row_col) {
                        return row_col.row + 1;
                    }
                },
                {
                    "data": "attendDate",
                    render: function (data, type, full) {
                        return new Date(data).format("yyyy-MM-dd");
                    }
                },
                {
                    "data": "attendWeek",
                    render: function (data, type, full) {
                        return week_CN[data - 1];
                    }
                },
                {
                    "data": "attendMorning",
                    render: function (data, type, full) {
                        if (data != null) {
                            return new Date(data).format("hh:mm:ss");
                        } else {
                            return "";
                        }
                    }
                },
                {
                    "data": "attendEvening",
                    render: function (data, type, full) {
                        if (data != null) {
                            return new Date(data).format("hh:mm:ss");
                        } else {
                            return "";
                        }
                    }
                },
                {
                    "data": "absence",
                    render: function (data, type, full) {
                        if (data != null) {
                            return data;
                        } else {
                            return "0";
                        }
                    }
                },
                {
                    "data": "attendStatus",
                    render: function (data, type, full) {
                        if (data == 1) {
                            return "<span style='color: green'>正常</span>";
                        } else {
                            return "<span style='color: red'>异常</span>";
                        }
                    }
                },
                {
                    "data": "操作列",
                    render: function (data, type, full) {
                        if (full.attendStatus == 2) {
                            return '<button type="button" class="btn btn-info"  onclick="return reAttend(' + JSON.stringify(full).replace(/\"/g, "'") + ')" >补签</button>'
                        } else {
                            return "";
                        }
                    }
                }
            ]
        }).api();   //此处需调用api()方法,否则返回的是JQuery对象而不是的API对象
        // js-end
    });

</script>
</body>
</html>
